<div class="row">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>系统菜单</h5>
                <div class="ibox-tools">
                    <!--<a class="collapse-link">-->
                        <!--<i class="fa fa-chevron-up"></i>-->
                    <!--</a>-->
                    <!--<a class="dropdown-toggle" data-toggle="dropdown" href="table_basic.html#">-->
                        <!--<i class="fa fa-wrench"></i>-->
                    <!--</a>-->
                    <!--<ul class="dropdown-menu dropdown-user">-->
                        <!--<li><a href="table_basic.html#">选项1</a>-->
                        <!--</li>-->
                        <!--<li><a href="table_basic.html#">选项2</a>-->
                        <!--</li>-->
                    <!--</ul>-->
                    <!--<a class="close-link">-->
                        <!--<i class="fa fa-times"></i>-->
                    <!--</a>-->
                </div>
            </div>
            <div class="ibox-content">
                <div class="">
                    <a  href="add" class="btn btn-primary btn-sm ">添加菜单</a>
                </div>
                <table class="table">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <!--<th>id</th>-->
                        <th>菜单名称</th>
                        <th>图标</th>
                        <th>父级菜单</th>
                        <th>模块</th>
                        <th>控制器</th>
                        <th>方法</th>
                        <th>是否显示</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {volist name="menuList" id="menu"}

                    <tr>
                        <td><input onblur="chengeSort({$menu.id},this.value)" value="{$menu.sort}" style="width: 36px;text-align: center" /></td>
                        <!--<td>{$menu.id}</td>-->
                        <td>{$menu.name}</td>
                        <td>{if $menu.icon}<i class="fa {$menu.icon}"></i>{/if}</td>
                        <td>-----</td>
                        <td>{$menu.m_name}</td>
                        <td>{$menu.c_name}</td>
                        <td>{$menu.a_name}</td>
                        <td>
                            {if $menu.is_show}
                            <button class="btn btn-danger btn-sm m-r-sm" onclick="toggleShow({$menu.id},0)">正在显示</button>
                            {else}
                            <button class="btn btn-danger btn-sm m-r-sm" onclick="toggleShow({$menu.id},1)">已隐藏</button>
                            {/if}
                        </td>
                        <td>
                            <a class="btn btn-danger btn-sm m-r-sm" href="destory?id={$menu.id}">删除</a>
                            <a class="btn btn-primary btn-sm m-r-sm" href="edit?id={$menu.id}">修改</a>

                        </td>
                    </tr>
                        {if $menu.child_count>0}

                            {volist name="menu.child" id="child"}

                                <tr>
                                    <td><input onblur="chengeSort({$child.id},this.value)" value="{$child.sort}" style="width: 36px;text-align: center" /></td>
                                    <!--<td>{$child.id}</td>-->
                                    <td>{$child.name}</td>
                                    <td>{if $child.icon}<i class="fa {$child.icon}"></i>{/if}</td>
                                    <td>{$menu.name}</td>
                                    <td>{$child.m_name}</td>
                                    <td>{$child.c_name}</td>
                                    <td>{$child.a_name}</td>
                                    <td>
                                        {if $child.is_show}
                                        <button class="btn btn-danger btn-sm m-r-sm" onclick="toggleShow({$child.id},0)">正在显示</button>
                                        {else}
                                        <button class="btn btn-danger btn-sm m-r-sm" onclick="toggleShow({$child.id},1)">已隐藏</button>
                                        {/if}
                                    </td>
                                    <td>
                                        <a class="btn btn-danger btn-sm m-r-sm" href="destory?id={$child.id}">删除</a>
                                        <a class="btn btn-primary btn-sm m-r-sm" href="edit?id={$child.id}">修改</a>
                                    </td>
                                </tr>

                            {/volist}


                        {/if}



                    {/volist}

                    <!--<tr>-->
                        <!--<td>1</td>-->
                        <!--<td>张三</td>-->
                        <!--<td>男</td>-->
                        <!--<td>23</td>-->
                        <!--<td>男</td>-->
                        <!--<td>-->
                            <!--<a class="btn btn-danger btn-sm m-r-sm" href="table_basic.html#">删除</a>-->
                            <!--<a class="btn btn-primary btn-sm m-r-sm" href="table_basic.html#">修改</a>-->
                        <!--</td>-->
                    <!--</tr>-->

                    </tbody>
                </table>

            </div>
        </div>
    </div>

</div>

<script>
    function toggleShow(id,isShow) {

        if(!id){
            alert('id不能为空')
            return
        }
        $.post('/menu/update?id='+id,{is_show:isShow},function (res) {

            if(res.code==1){
                // window.parent.location.reload(true);
                location.reload(true)
            }
        })

    }

    function  chengeSort(id,val) {
        console.log(id,val)
        var sort = parseInt(val)

        $.post('/menu/update?id='+id,{sort:sort},function(res){
            if(res.code==1){
                location.reload(true)
            }
        })
    }
</script>